/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucmconfchecker.conformance;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author Administrador
 */
public class Report<T> {
    
    private boolean _precedence = true;
    private boolean _missingEvent = true;
    private boolean _missingPrecondition = true;
    private boolean _unexpectedEvent = true;
    
    private Map<T,T> precedenceConflicts = new HashMap<T,T>();
    private Set<T> missingEventConflicts = new HashSet<T>();
    private Map<T,T> missingPreconditionConflicts = new HashMap<T,T>();
    private Set<T> unexpectedEventConflicts = new HashSet<T>();
    
    private Set<T> withoutConflict = new HashSet<T>();

//    private int missingPreconditionCounter=0;
//    private int unexpectedEventCount=0;
//    private int missingEventCounter=0;
//    private int precedenceConflictCounter=0;
//    private int widthoutConflictCounter=0;

    public boolean isPrecedence() {
        return _precedence;
    }

    public boolean isMissingEvent() {
        return _missingEvent;
    }

    public boolean isMissingPrecondition() {
        return _missingPrecondition;
    }

    public boolean isUnexpectedEvent() {
        return _unexpectedEvent;
    }

    public Map<T,T> getPrecedenceConflicts() {
        return precedenceConflicts;
    }

    public Set<T> getMissingEventConflicts() {
        return missingEventConflicts;
    }

    public Map<T,T> getMissingPreconditionConflicts() {
        return missingPreconditionConflicts;
    }

    public Set<T> getUnexpectedEventConflicts() {
        return unexpectedEventConflicts;
    }

    public Set<T> getWithoutConflict() {
        return withoutConflict;
    }
    
    public void addUnexpectedEvent(Event<T> event){
        unexpectedEventConflicts.add(event.getEvent());
//        unexpectedEventCount++;
    }
    public void addMissingPrecondition(Event<T> event, T conflict){
        missingPreconditionConflicts.put(event.getEvent(),conflict);
//        missingPreconditionCounter++;
    }
    public void addMissingEvent(T event){
        missingEventConflicts.add(event);
//        missingEventCounter++;
    }
    public void addPrecedenceConflict(Event<T> event, Event<T> conflict){
        precedenceConflicts.put(event.getEvent(),conflict.getEvent());
//        precedenceConflictCounter++;
    }
    public void addWidthoutConflict(T element){
        withoutConflict.add(element);
//        widthoutConflictCounter++;
    }

    public int getMissingPreconditionCounter() {
        return missingPreconditionConflicts.size();
    }

    public int getUnexpectedEventCount() {
        return unexpectedEventConflicts.size();
    }

    public int getMissingEventCounter() {
        return missingEventConflicts.size();
    }

    public int getPrecedenceConflictCounter() {
        return precedenceConflicts.size();
    }

    public int getWidthoutConflictCounter() {
        return withoutConflict.size();
    }
    
    public static <T> Report<T> merge(Collection<Report<T>> reports){
        Report<T> result = new Report<T>();
        for(Report<T> report:reports){
            result.getMissingEventConflicts().addAll(report.getMissingEventConflicts());
            result.getMissingPreconditionConflicts().putAll(report.getMissingPreconditionConflicts());
            result.getPrecedenceConflicts().putAll(report.getPrecedenceConflicts());
            result.getUnexpectedEventConflicts().addAll(report.getUnexpectedEventConflicts());
            result.getWithoutConflict().addAll(report.getWithoutConflict());
        }
        return result;
    }
    
}
